package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtUserAddress;
import com.ruoyi.business.service.IJtUserAddressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户地址Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/address")
public class JtUserAddressController extends BaseController
{
    private String prefix = "business/address";

    @Autowired
    private IJtUserAddressService jtUserAddressService;

    @RequiresPermissions("business:address:view")
    @GetMapping()
    public String address()
    {
        return prefix + "/address";
    }

    /**
     * 查询用户地址列表
     */
    @RequiresPermissions("business:address:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtUserAddress jtUserAddress)
    {
        startPage();
        List<JtUserAddress> list = jtUserAddressService.selectJtUserAddressList(jtUserAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址列表
     */
    @RequiresPermissions("business:address:export")
    @Log(title = "用户地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtUserAddress jtUserAddress)
    {
        List<JtUserAddress> list = jtUserAddressService.selectJtUserAddressList(jtUserAddress);
        ExcelUtil<JtUserAddress> util = new ExcelUtil<JtUserAddress>(JtUserAddress.class);
        return util.exportExcel(list, "用户地址数据");
    }

    /**
     * 新增用户地址
     */
    @RequiresPermissions("business:address:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户地址
     */
    @RequiresPermissions("business:address:add")
    @Log(title = "用户地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtUserAddress jtUserAddress)
    {
        return toAjax(jtUserAddressService.insertJtUserAddress(jtUserAddress));
    }

    /**
     * 修改用户地址
     */
    @RequiresPermissions("business:address:edit")
    @GetMapping("/edit/{addressId}")
    public String edit(@PathVariable("addressId") Long addressId, ModelMap mmap)
    {
        JtUserAddress jtUserAddress = jtUserAddressService.selectJtUserAddressByAddressId(addressId);
        mmap.put("jtUserAddress", jtUserAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户地址
     */
    @RequiresPermissions("business:address:edit")
    @Log(title = "用户地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtUserAddress jtUserAddress)
    {
        return toAjax(jtUserAddressService.updateJtUserAddress(jtUserAddress));
    }

    /**
     * 删除用户地址
     */
    @RequiresPermissions("business:address:remove")
    @Log(title = "用户地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtUserAddressService.deleteJtUserAddressByAddressIds(ids));
    }
}
